/*
 * module_init.c
 *
 *  Created on: 2021年3月23日
 *      Author: Jiarun
 */

#include "module_init.h"
#include "zf_gpt12.h"


/**
 * @brief  各类初始化
 * @param  None
 * @return None
 */

void PID_init(void)
{
    //左电机PID初始化
    pid.P = 52; //80
    pid.I = 2.3;//2.5;
    pid.D = 16;  //20
}

void module_init(){

    /**电机PWM**/
    PID_init();
    gtm_pwm_init(MOTOR_PIN,   17000, 0);
    gtm_pwm_init(MOTOR_INVER, 17000, 0);
    /*舵机*/
    gtm_pwm_init(Servo_PIN, 60, Servo_Median);     //duty[1000,5000];

    key_init();
    lcd_init();
    Param_load();

    if(global_param.AUTO_EXP){
        MT9V03X_CFG[AUTO_EXP-1][1] = 63;
    }else{
        MT9V03X_CFG[AUTO_EXP-1][1] = 0;
    }
    MT9V03X_CFG[GAIN-1][1] = global_param.GAIN;

    mt9v03x_init();     //摄像头初始化

    ADC_Init(ADC6, 80000);              //测距
    gpt12_init(GPT12_T2, GPT12_T2INB_P33_7, GPT12_T2EUDB_P33_6);    //方向编码器
    gpio_init(P33_5, GPO, 0, PUSHPULL);    //蜂鸣器

    /***配置周期中断并失能***/
    pit_interrupt_ms(CCU6_0, PIT_CH0, 6);
    pit_interrupt_ms(CCU6_1, PIT_CH0, 11);
    pit_disable_interrupt(CCU6_0, PIT_CH0);
    pit_disable_interrupt(CCU6_1, PIT_CH0);
}

